<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/web/header.jsp"%>
<title>Insert title here</title>
</head>
<body>
	<fieldset class="layui-elem-field" style="margin: 20px; padding: 15px;">
		<legend>员工维护--修改部门</legend>
		<form class="layui-form" lay-filter="formA" method="post">
			<div class="layui-form-item">
				<label class="layui-form-label">编号</label>
				<div class="layui-input-inline">
					<input type="text" name="code" readonly lay-verify="required" placeholder="请输入编号" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">部门</label>
				<div class="layui-input-inline">
					<select name='codeDept'></select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"></label>
				<div class="layui-input-inline">
					<input type="button" class="layui-btn" lay-submit lay-filter="updDept" value="确定" />
					<input type="button" class="layui-btn" onclick="closeThis()" value="取消" />
				</div>
			</div>
			<input type="hidden" name="action" value="updDept" />
		</form>
	</fieldset>
	<script type="text/javascript">
initSel();
function initSel(){
	ajax("/DepartServlet",{action:'list'},'json',function(data){
		var temp="<option value=''>请选择部门</option>";
	    $.each(data,function(){
	    	temp+="<option value='"+this.id+"'>"+this.name+"</option>"
	    })
	    $("select[name='codeDept']").html(temp);
	    form.render();
	    init();
    });
}
function init(){
    var code = '<%=request.getParameter("code")%>';
			ajax("/EmployeeServlet", {
				action : 'get',
				code : code,
			}, 'json', function(data) {
				form.val("formA", {
					code : data.id,
					codeDept : data.d_id,
				})
			});
		}
		formSubmit('/EmployeeServlet', 'submit(updDept)', 'text',
				function(data) {
					if (data == 1) {
						layer.msg('修改成功', closeThis);
					} else {
						layer.msg('修改失败');
					}
				});
	</script>
</body>
</html>